package com.apci.ipreda.util;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.regex.Pattern;

import com.apci.ipreda.domain.TipoDataBase;

public class CommonUtil {
	
	public static String PATTERN_LETRAS = "[A-Za-z_ ]+";
	
	public static List<String> getAnnoDeclaracionList(){
		List<String> annoList = new ArrayList<String>();
		annoList.add("2010");
		annoList.add("2011");
		annoList.add("2012");
		return annoList;
	}
	public static List<TipoDataBase> getYesNoList(){
		List<TipoDataBase> yesNoList = new ArrayList<TipoDataBase>();
		TipoDataBase tipoDataBase = new TipoDataBase();
		tipoDataBase.setCodigo("S");
		tipoDataBase.setDescripcion("SI");
		yesNoList.add(tipoDataBase);
		tipoDataBase = new TipoDataBase();
		tipoDataBase.setCodigo("N");
		tipoDataBase.setDescripcion("NO");
		yesNoList.add(tipoDataBase);
		return yesNoList;
	}
	
	public static String getDateFormatted(Date dateUser, String template) {
		if (template==null) {template = "dd-MMM-yyyy"; }
		if (template.equals("")) {template = "dd-MMM-yyyy"; }
		SimpleDateFormat dateFormat = new SimpleDateFormat(template);
	    return dateFormat.format(dateUser);
	}
	public static Date getDateFromAsFormat(String date, String format) throws Exception{
		if (format==null) {format = "dd-MMM-yyyy"; }
		if (format.equals("")) {format = "dd-MMM-yyyy"; }
		SimpleDateFormat formatDate = new SimpleDateFormat(format);
		return formatDate.parse(date);
	}
	public static String getTodayAsFormat(String format) throws Exception{
		if (format==null) {format = "dd-MMM-yyyy"; }
		if (format.equals("")) {format = "dd-MMM-yyyy"; }
		Calendar calendario = GregorianCalendar.getInstance();
		Date fecha = calendario.getTime();
		System.out.println(fecha);
		SimpleDateFormat formatoDeFecha = new SimpleDateFormat(format);
		return formatoDeFecha.format(fecha);
	}
	public static boolean validaPattern(String pattern, String text){
		boolean isMatch = Pattern.matches(pattern, text);
		return isMatch;
	}

	public static void main(String[] args) {
		
		boolean isMatch = Pattern.matches("[A-Za-z_ ]+", "ssss  s");
		System.out.println(isMatch);
		
		try {
			//System.out.println(getDateFromAsFormat(getTodayAsFormat(null), null));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
